//
//  SingleFireSignal.hpp
//  sad
//
//  Created by Christopher Kemsley on 4/20/12.
//  Copyright (c) 2012 iAppolopolis. All rights reserved.
//

#ifndef sad_SingleFireSignal_hpp
#define sad_SingleFireSignal_hpp

#include "SystemCDefinitions.hpp"





struct NonDuplicatingNotification : public sc_module
{
	SC_HAS_PROCESS(NonDuplicatingNotification) ;
	
	NonDuplicatingNotification ( sc_module_name const & name )
	:	sc_module(name)
	,	mEvent ()
	,	mDidFire(false)
		{
		SC_THREAD ( runLoop ) ;
		}
	
	
	void	wait () const
		{
		::wait ( mEvent ) ;
		}
	void	wait ( SCInterval const & timeout ) const
		{
		::wait ( timeout , mEvent ) ;
		}
	
	void	fire ()
		{
		if ( ! mDidFire )
			{
			mEvent . notify ( 0 , kSCIntervalSeconds ) ;
			mDidFire = true ;
			}
		}
	
	
private:
	sc_event	mEvent ;
	bool		mDidFire ;
	
	void runLoop ()
		{
		while ( 1 )
			{
			::wait ( mEvent ) ;
			mDidFire = false ;
			}
		}
} ;





#endif
